#include <libdbus-cpp/low-level/connection.h>

namespace dbus {
namespace lowlevel {


Connection::Connection(e_bustype type) {
	switch (type) {
		case SystemBus: m_connection = dbus_bus_get(DBUS_BUS_SYSTEM,&m_error);
			break;
		case SessionBus: m_connection = dbus_bus_get(DBUS_BUS_SESSION,&m_error);
			break;
	}
	this->InternalInit();
}

Connection::Connection(const std::string& path) {
	m_connection = dbus_connection_open(path.c_str(),&m_error);
	this->InternalInit();  
}

// Extra initialisation done for any of the 
void Connection::InternalInit() {
	if (0==m_connection) throw dbus::Exception(m_error);
}

Connection::~Connection () {
	dbus_connection_unref(m_connection);
}


}; // namespace low_level
}; // namespace dbus
